package top.idetect.client.modules.cloth.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.idetect.client.common.api.CommonPage;
import top.idetect.client.common.api.CommonResult;
import top.idetect.client.modules.cloth.model.Clothinfo;
import top.idetect.client.modules.cloth.service.ClothinfoService;

import java.util.HashMap;

import static top.idetect.client.schedule.IpUpdateTask.ipList;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wjh
 * @since 2024-03-15
 */
@RestController
@RequestMapping("/cloth/clothinfo")
public class ClothinfoController {

    @Autowired
    private ClothinfoService clothinfoService;


    @ApiOperation("分页查询批次数据")
    @GetMapping("/page")
    @ResponseBody
    public CommonResult page(@RequestParam(value = "keyword" ,required = false) String keyword,
                             @RequestParam(value = "deviceName" ,required = false) String deviceName,
                             @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        Page<Clothinfo> page = clothinfoService.page(pageSize, pageNum, keyword, deviceName);
        return CommonResult.success(CommonPage.restPage(page));
    }


    @ApiOperation("查询单批次数据")
    @GetMapping("/get")
    @ResponseBody
    public CommonResult get(@RequestParam(value = "clothSerial" ,required = false) String clothSerial) {
//        HashMap<String, Object> map = new HashMap<>();
//        if(StrUtil.isNotEmpty(clothSerial)){
//            map.put("cloth_serial", clothSerial);
//        }
//        return CommonResult.success(clothinfoService.listByMap(map).get(0));
        return CommonResult.success(clothinfoService.getByClothSerial(clothSerial));
    }

}

